package com.zmn.plat.services.impl.pilot;

import com.zmn.common.constant.GlobalConsts;
import com.zmn.common.utils.date.DateUtil;
import com.zmn.plat.model.entity.pilot.ServCityPriceLog;
import com.zmn.plat.model.entity.pilot.ServCityPriceLogQuery;
import com.zmn.plat.persistence.interfaces.pilot.ServCityPriceLogDao;
import com.zmn.plat.services.interfaces.pilot.ServCityPriceLogService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;

import javax.annotation.Resource;
import java.util.List;
import java.util.Objects;

/**
 * 描述: 城市试点日志接口实现类
 *
 * @author guoqiao
 * @since 2021-06-25 10:17:20
 */
@Slf4j
@Service
public class ServCityPriceLogServiceImpl implements ServCityPriceLogService {

    private static final String TAG = "城市试点日志基础服务接口";

    @Resource
    private ServCityPriceLogDao servCityPriceLogDao;

    @Override
    public ServCityPriceLog findById(Integer logId) {

        if (Objects.isNull(logId)) {
            log.error("[{}],根据id查询数据logId为null", TAG);
            return null;
        }
        return servCityPriceLogDao.findById(logId);
    }

    @Override
    public List<ServCityPriceLog> listPageByQuery(ServCityPriceLogQuery query) {

        if (Objects.isNull(query)) {
            log.error("[{}],按条件查询数据,query为null", TAG);
            return null;
        }
        query.setTotalCount(servCityPriceLogDao.countByQuery(query));
        return servCityPriceLogDao.listPageByQuery(query);
    }

    @Override
    public List<ServCityPriceLog> listByQuery(ServCityPriceLogQuery query) {

        if (Objects.isNull(query)) {
            log.error("[{}],按条件查询数据,query为null", TAG);
            return null;
        }
        return servCityPriceLogDao.listByQuery(query);
    }

    @Override
    public Integer countByQuery(ServCityPriceLogQuery query) {

        if (Objects.isNull(query)) {
            log.error("[{}],按条件统计数据,query为null", TAG);
            return null;
        }
        return servCityPriceLogDao.countByQuery(query);
    }

    @Override
    public Integer updateByKey(ServCityPriceLog servCityPriceLog) {

        if (Objects.isNull(servCityPriceLog.getLogId())) {
            log.error("[{}],根据id修改数据,servCityPriceLog为null", TAG);
            return null;
        }
        return servCityPriceLogDao.updateByKey(servCityPriceLog);
    }

    @Override
    public void updateStatusBatch(List<Integer> ids, Integer status, String operator) {

        if (!Objects.equals(status, GlobalConsts.NO) && !Objects.equals(status, GlobalConsts.YES)) {
            log.error("[{}],status状态超出取值范围", TAG);
            return;
        }
        servCityPriceLogDao.updateStatusBatch(ids, status, operator, DateUtil.getNow());
    }

    @Override
    public Integer insert(ServCityPriceLog servCityPriceLog) {

        if (Objects.isNull(servCityPriceLog)) {
            log.error("[{}],新增数据,servCityPriceLog为null", TAG);
            return null;
        }
        return servCityPriceLogDao.insert(servCityPriceLog);
    }

    @Override
    public Integer insertBatch(List<ServCityPriceLog> servCityPriceLog) {

        if (CollectionUtils.isEmpty(servCityPriceLog)) {
            log.error("[{}],新增数据,servCityPriceLog为null", TAG);
            return null;
        }
        return servCityPriceLogDao.insertBatch(servCityPriceLog);
    }


    @Override
    public Integer deleteByKey(Integer logId) {

        if (Objects.isNull(logId)) {
            log.error("[{}],根据id删除数据,logId为null", TAG);
            return null;
        }
        return servCityPriceLogDao.deleteByKey(logId);
    }

}